namespace jQube.Web.UI.Design
{
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.Design;
    using jQube.Web.UI.Controls;

    public class AccordionDesigner : ControlDesigner
    {
        private Accordion accordion;

        public AccordionDesigner()
        {
        }

        internal new Accordion Component
        {
            get
            {
                return this.accordion;
            }
        }

        public override void Initialize(IComponent component)
        {
            this.accordion = component as Accordion;

            if (component == null)
                throw new ArgumentException("The component must be an Accordion control", "component");

            base.Initialize(component);
        }

        public override string GetDesignTimeHtml()
        {
            StringBuilder html = new StringBuilder();

            html.AppendFormat("<div id=\"{0}\">", accordion.ID);

            foreach (AccordionPane pane in this.Component.Panes)
            {
                //string headerCSS = !string.IsNullOrEmpty(pane.HeaderCssClass) ? pane.HeaderCssClass : _accordion.HeaderCssClass;
                //html.AppendFormat("<div class=\"{0}\">", headerCSS);
                html.AppendFormat("<div id=\"{0}\">", pane.ID);

                TemplateBuilder builder = pane.Header as TemplateBuilder;

                if (builder != null)
                {
                    html.Append("<div>");
                    html.Append(builder.Text);
                    html.Append("</div>");
                }

                //html.Append("</div>");

                //string contentCSS = !string.IsNullOrEmpty(pane.ContentCssClass) ? pane.ContentCssClass : _accordion.ContentCssClass;
                //html.AppendFormat("<div class=\"{0}\">", contentCSS);


                builder = pane.Content as TemplateBuilder;

                if (builder != null)
                {
                    html.Append("<div>");
                    html.Append(builder.Text);
                    html.Append("</div>");
                }
                
                html.Append("</div>");
            }

            html.Append("</div>");

            Console.Write(html.ToString());

            return html.ToString();
        }
    }

}
